import { Component, OnInit, ViewChild, OnDestroy, AfterContentInit } from '@angular/core';
import { FormGroup, FormBuilder, Validators } from '@angular/forms';
import { NzMessageService, UploadFile, NzModalService, NzNotificationService } from 'ng-zorro-antd';
import { catchError } from 'rxjs/operators';
import { of } from 'rxjs';
import { ActivatedRoute, Router } from '@angular/router';
import {SettingsService, TitleService} from '@delon/theme';
import { Constant, ServiceResult } from '@core/constant';
import { maService } from '../../../../service/ma/ma.service';
import { EmitterService } from 'app/service/emit.service';
import { CommService } from '../../../../service/comm/comm.service';
import {maListService} from '../../../../service/maList/maList.service';
import {blListService} from "../../../../service/blList/blList.service";

@Component({
  selector: 'blList-view-edit',
  templateUrl: './blList-edit.component.html',
  styleUrls: ['./blList-edit.component.less']
})
export class blListEditComponent implements OnInit, OnDestroy {
  product:  any = {
    blKuanhao: "",
    blPinpai: "",
    blPinxiang: "",
    blSrmx1: "",
    blSrmx10: "",
    blSrmx11: "",
    blSrmx12: "",
    blSrmx13: "",
    blSrmx14: "",
    blSrmx15: "",
    blSrmx16: "",
    blSrmx17: "",
    blSrmx18: "",
    blSrmx19: "",
    blSrmx2: "",
    blSrmx20: "",
    blSrmx21: "",
    blSrmx22: "",
    blSrmx3: "",
    blSrmx4: "",
    blSrmx5: "",
    blSrmx6: "",
    blSrmx7: "",
    blSrmx8: "",
    blSrmx9: "",
    blVersion: "",
    blXuhao: "",
    id: "",
    lifnr: "",
    name1: ""
  };
  tabIndex = 0;
  private sub: any;
  // 预览图片对象
  previewImage = '';
  // 是否可以预览
  previewVisible = false;
  uploadUrl = '';
  loading = false;
  constructor(
    public setting: SettingsService,
    private msg: NzMessageService,
    private modalService: NzModalService,
    private emit: EmitterService,
    private notification: NzNotificationService,
    private route: ActivatedRoute,
    private titleService: TitleService,
    private blListService: blListService,
    private cnt: Constant,
    private router: Router,
    private comm: CommService
  ) {}
  ngOnInit(): void {
    // 获取参数
    this.sub = this.route.params.subscribe(params => {
      this.product.id = params["id"]
      this.getProductInfo();
    });
    // 隐藏reusetab
    // setTimeout(() => {
    //   this.emit.sendMessage("HIDE_REUSE_TAB");
    // }, 10);
  }
  // 显示reusetab
  ngOnDestroy() {
    this.emit.sendMessage("SHOW_REUSE_TAB");
  }
  changeTab(index) {
    // 使用异步的方式更新组件, 防止ngIf错误
    Promise.resolve(null).then(() => this.tabIndex = index);
  }
  getProductInfo() {
    this.blListService.getlfa1detail(this.product.id).pipe(
      catchError(err => {
        return of(err);
      })
    ).subscribe(data => {
      this.product = data.data;
    })
  }
  back() {
    this.router.navigate(['/blList/blList']);
  }
  save() {
    let fxjLoanins = {
      id:this.product.id,
      lmatnr:this.product.lmatnr,
      lmaktx:this.product.lmaktx
    };
    // 调用接口
    this.blListService.editLfa1(fxjLoanins).pipe(
      catchError(err => {
        return of(err);
      })
    ).subscribe(data => {
      if (data.ok === true) {
        this.msg.success('修改成功');
        this.back();
        this.emit.sendMessage("RELOAD_GOODS_LIST");
      } else {
        this.msg.error(data['message']);
      }
    })
  }
}
